<!-- 调拨单记录 -->
<template>
  <div id="change">
    <div class="change-top">
      单据号
      <el-input size="small" style="width: 200px;margin-left: 10px;margin-right: 20px;" placeholder="请输入单据号"
        v-model="input" clearable>
      </el-input>
      日期&nbsp;&nbsp;
      <el-date-picker style="width: 260px;" size="small" :unlink-panels="true" v-model="value1" type="daterange"
        range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
      </el-date-picker>
      业务类别
      <el-select size="small" style="width: 120px;margin-left: 10px;margin-right: 20px;" v-model="input" clearable>
      </el-select>
      仓库
      <el-select size="small" style="width: 120px;margin-left: 10px;margin-right: 20px;" v-model="input" clearable>
      </el-select>
      <!-- <el-button size="small" style="margin-left: 10px;" type="primary">查询</el-button>
      <el-button size="small" type="primary" @click="goto('addChange')">新增</el-button>
      <el-button size="small" type="primary">导入</el-button>
      <el-button size="small" type="primary">导出</el-button> -->
      <PublicButton add="addInBound" />
    </div>
    <div class="change-content">
      <el-table :summary-method="getSummaries" height="500px" :data="pageInfo.list" border
        style="width: 100%;font-size: 13px;">
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column prop="createDate" label="单据日期" width="150">
        </el-table-column>
        <el-table-column prop="truckingNumber" label="单据编号" width="120">
        </el-table-column>
        <el-table-column prop="bKind" label="业务类别" width="120">
        </el-table-column>
        <el-table-column label="明细" width="400">
          <template slot-scope="scope">
            <table id="contact-table" style="width: 100%; text-align:center;">
              <tr>
                <th>商品名称</th>
                <th>数量</th>
                <th>金额</th>
              </tr>
              <tr v-for="(detail, index) in scope.row.detailList" :key="index">
                <td>{{ detail.goodname }}</td>
                <td>{{ detail.unitPrice }}</td>
                <td>{{ detail.num }}</td>
              </tr>
              <tr>
                <td>合计</td>
                <td></td>
                <td></td>
              </tr>
            </table>
          </template>

        </el-table-column>
        <!-- <el-table-column prop="pid" label="金额" width="120">
        </el-table-column> -->
        <el-table-column prop="providerName" label="供应商" width="150">
        </el-table-column>
        <el-table-column prop="employeeName" label="业务员" width="120">
        </el-table-column>
        <el-table-column prop="mid" label="制单人" width="120">
        </el-table-column>
        <el-table-column prop="aid" label="审核人" width="120">
        </el-table-column>
        <!-- <el-table-column prop="detailRemark" label="备注" width="150">
        </el-table-column> -->
        <!-- <el-table-column prop="aboutCode" label="关联物流单号" width="150">
        </el-table-column> -->
        <!-- <el-table-column prop="state" label="对单状态" width="120">
        </el-table-column> -->
        <el-table-column fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" circle @click="inBoundUpdate(scope.row)"></el-button>
            <el-button type="danger" @click="deleteInBound(scope.row.inBoundId)" icon="el-icon-delete"
              circle></el-button>
          </template>
        </el-table-column>
      </el-table>

    </div>
    <el-pagination style="width: 400px;position: relative;left: 700px;bottom: 30px;"
      @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-size="pageInfo.pageSize"
      layout="total, prev, pager, next, jumper" :total="pageInfo.total">
    </el-pagination>

  </div>
</template>

<script>
import PublicButton from '../public_com/PublicButton.vue';
import AddInBound from './AddInBound.vue';

export default {
  name: 'InBoundList',
  components: {
    AddInBound,
    PublicButton
  },
  data() {
    return {
      //新增对话框
      dialogFormVisible: false,
      switchValue: '1',
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }, {
        value: '选项4',
        label: '龙须面'
      }, {
        value: '选项5',
        label: '北京烤鸭'
      }],
      value: '',
      input: '',
      // inBoundList: [
      // ],
      value1: '',
      pageInfo: {},
      detailList: []
    }
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.getPage(val, 5)
    },
    goto(to) {
      this.$router.push(to)
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (column.property === "num") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
        }
      });

      return sums;
    },
    //分页
    getPage(pageNum, pageSize) {
      this.axios.get('/store/ib/getPage',
        {
          params: {
            pageNum, pageSize
          }
        }
      ).then(rs => {
        if (rs.data.pageInfo != null) {
          this.pageInfo = rs.data.pageInfo
        }
      })
    },
    //获取所有的入库明细
    // getDetailList() {
    //   this.axios.get('/store/detail/getAllDetail').then(rs => {
    //     this.detailList = rs.data.details
    //     this.getPage(1, 5)
    //   })
    // },
    deleteInBound(inBoundId) {
      this.$confirm('删除该条入库单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios.get('/store/ib/deleteInBound',
          {
            params: {
              inBoundId
            }
          }
        ).then(rs => {
          if (rs.data.code == 200) {
            this.successMessage("删除成功")
            this.getPage(1, 5)
          } else {
            this.errorMessage("删除出错了")
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },
    successMessage(msg) {
      this.$message({
        message: msg,
        type: 'success'
      });
    },
    errorMessage(msg) {
      this.$message({
        message: msg
        ,
        type: 'error'
      })
    },
    inBoundUpdate(row) {
      this.$router.push({
        path: 'updateInBound',
        query: {
          row
        }
      })
      console.log(row)
    }
  },
  created() {
    this.getPage(1, 5)
  }

}
</script>

<style scoped>
#change {
  width: 100%;
  height: 100%;
}

.change-top {
  width: calc(100% -20px);
  height: 60px;
  /* background-color: pink; */
  line-height: 60px;
  padding-left: 20px;
  font-size: 13px;
}

.change-content {
  width: 100%;
  height: calc(100% - 60px);
  /* background-color: skyblue; */
}

.el-input,
.el-button {
  font-size: 13px;
}

/* 合计行整体样式修改开始 */
.el-table /deep/ .el-table__footer-wrapper tbody td,
.el-table /deep/ .el-table__fixed-footer-wrapper tbody td {
  background-color: #fff1d4;
}

.el-table /deep/ tbody tr:hover>td {
  background-color: #fff1d4;
}

#contact-table {
  border-collapse: collapse;
  text-align: center;
}

#contact-table th,
#contact-table td {
  border: 1px solid gray;
  padding: 0px;
}
</style>